// ActionScript file
package
{
	
	
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	//import sunag.sea3d.environment.Background;
	
	public class LoadImage extends Sprite
	{
		
		private var imagesData:Array=[];    
		public var loaderAry:Array=[];   
		public var newLoaderAry:Array=[];  
		private var i:int=0;   
		private var len:Number;
		private var Width:int;
		private var Height:int;
		private var X:int;
		private var Y:int;
		private var Center:Boolean;
		public function LoadImage(width:int,height:int,x:int,y:int,center:Boolean=false):void{    
			//_localModel=LocalModel.getInstance();
			this.Width=width;
			this.Height=height;
			this.X=x;
			this.Y=y;
			this.Center=center;
			trace(width+" "+height+" "+X+" "+Y);
		} 
		public function set path(datas:Array):void{ 
			newLoaderAry=[];
			
			imagesData=datas.slice();  
			len=imagesData.length
			loadeder();
			
		} 
		public function get Pic():Array
		{
			return newLoaderAry;
		}
		private function completeHandler(e:Event):void {  
			e.target.removeEventListener(Event.COMPLETE,completeHandler);   
			var s:Sprite=e.target as Sprite;  
			
			var _num:Number=90/s.height
			var w:Number =Width;
			var h:Number =Height;
			
			s.width = w;
			s.height = h;
			s.x=X;
			s.y=Y;
			//s.name=_localModel.configXml.picload.child(i).@name;
			this.addChild(s);  
			loaderAry.push(s); 
			newLoaderAry.push(s)
			if(imagesData.length<1){ 
				trace("allcomplete")
				this.dispatchEvent(new Event("ALLCOMPLETE"));//发送图片全部加载完成事件    
			}else{     
				loadeder();     
				i++;    
			}         
		}  
		private function loadeder():void{  
			
			if(imagesData.length>0){     
				var obj:String=imagesData.shift();  
				trace("path++"+obj)
				var ball:OrigImage=new OrigImage(Center);    
				ball.path=String(obj)
				ball.addEventListener(Event.COMPLETE,completeHandler); 
				//ball.name="PicBtn_"+String(String(obj.split(".")[0]).split("/").pop());
				trace(ball.name)
			}   
		}       
		private function ioErrorHandler(event:Event):void {           
			trace("ioErrorHandler: " + event);   
			if(imagesData.length>0){     
				i++;    
			}       
		}    
		public function dispose():void {  
			for(var K:int=0;K<loaderAry.length;K++){
				loaderAry[K].dispose();
				loaderAry[K]=null
			}
			
			var len:int=this.numChildren;
			for(var i:int=0;i<len;i++){
				this.removeChildAt(0);  
			}
			i=0;
			imagesData=[];
			loaderAry=[];
		}
	}}